﻿using Android.App;
using Android.OS;
using Android.Widget;
using System.IO;
using Android.Graphics;

namespace NativeTest
{
    [Activity(Label = "NativeTest", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        private string file = "cha_2d_card_01001.scr";
        private string filepath = "/data/data/NativeTest.NativeTest/files/";

        private void Decode()
        {
            byte[] content = File.ReadAllBytes(filepath + file);
            byte[] decode = NativePlugin.DecodeRotData(content);
            //File.WriteAllBytes(filepath + file.Replace("scr", "jpg"), decode);
            ImageView image = FindViewById<ImageView>(Resource.Id.MyImage);
            Bitmap bm = BitmapFactory.DecodeByteArray(decode, 0, decode.Length);
            image.SetImageBitmap(bm);
        }

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            //Copy file
            using (var asset = Assets.Open(file))
            using (var dest = File.Create(filepath + file))
            {
                asset.CopyTo(dest);
            }

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

            //button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
            button.Click += delegate { Decode(); };
        }
    }
}

